﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;

namespace FangDuShi_Admin.BLL
{
    /// <summary>
    /// 后台登录逻辑类
    /// </summary>
    public class Login
    {
        public Login()
        {

        }

        /// <summary>
        /// 得到一个对象实体,根据用户登陆号、密码
        /// <creator>wangl</creator>
        /// <date>2012-06-01</date>
        /// </summary>
        /// <param name="loginid"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public Model.PrvUser GetModelByNameAndPassword(string loginID, string password)
        {
            DAL.PrvUser prvUserDAL = new DAL.PrvUser();
            string newPassword = GetMd5Password(loginID, password);
            return prvUserDAL.GetModelByLoginIDAndPassword(loginID, newPassword);
        }


        public void EditPassword(string loginID, string password)
        {
            DAL.PrvUser prvUserDAL = new DAL.PrvUser();
            string newPassword = GetMd5Password(loginID, password);
               prvUserDAL.EditPassword(loginID, newPassword);
        }
        /// <summary>
        /// 得到一个对象实体
        /// <creator>wangl</creator>
        /// <date>2012-07-25</date>
        /// </summary>
        /// <param name="logid"></param>
        /// <param name="password"></param>
        /// <param name="entityNo"></param>
        /// <returns></returns>
        public Model.PrvUser GetModel(string loginID)
        {
            DAL.PrvUser prvUserDAL = new DAL.PrvUser();
            return prvUserDAL.GetModel(loginID);
        }
        /// <summary>
        /// 更新用户登录信息
        /// <creator>wangl</creator>
        /// <date>2012-06-01</date>
        /// </summary>
        /// <param name="loginID"></param>
        /// <param name="lastLoginIpAddr"></param>
        /// <param name="loginType"></param>
        public void UpdateUserLoginMsg(string loginID, string lastLoginIpAddr)
        {
            DAL.PrvUser prvUserDAL = new DAL.PrvUser();
            prvUserDAL.UpdateUserLoginMsg(loginID, lastLoginIpAddr);
        }

        public List<Model.PrvUser> GetPrvUserListAll()
        {

             DAL.PrvUser prvUserDAL = new DAL.PrvUser();
             return prvUserDAL.GetPrvUserListAll();
        }
        #region 私有方法
        /// <summary>
        /// 根据公司编号,用户登录名跟密码获取MD5密码
        /// <creator>wangl</creator>
        /// <date>2012-06-01</date>
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        private string GetMd5Password(string loginID, string password)
        {
            string newPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(loginID + password, "MD5");
            return newPassword;
        }
        #endregion
    }
}
